package cm.iccsoft.android.telecomcost.entities;

import java.util.ArrayList;
import java.util.Calendar;

public class WeeklyThreshold extends Threshold {

	private Week week;;
	private double _mondayTreshold;
	private double _tuesdayTreshold;
	private double _wednesdayTreshold;
	private double _thursdayTreshold;
	private double _fridayTreshold;
	private double _saturdayTreshold;
	private double _sundayTreshold;

	public WeeklyThreshold(double d, int weekOfMonth, int month) {
		super(d);
		week = new Week();
		week.setWeekOfMonth(weekOfMonth);
		week.setMonth(month);
	}

	public WeeklyThreshold() {
	}

	public WeeklyThreshold(double threshold, int weekOfMonth, Month month) {
		super(threshold);
		week = new Week();
		week.setWeekOfMonth(weekOfMonth);
		week.setMonth(month);
	}

	@Override
	public String getType() {
		return "WeeklyThreshold";
	}

	@Override
	public void setType(String type) {
	}

	@Override
	public TimePeriod getPeriod() {
		return TimePeriod.WEEK;
	}

	@Override
	public void setPeriod(TimePeriod _period) {
		// do nothing, the period is fixed
	}

	@Override
	public String toString() {
		return "Week " + week.getWeekOfMonth() + " ( " + getAmount() + " )";
	}

	public static final String PROP_TYPE = "WeeklyThreshold";	
	public static int[] daysOfWeek = new int[]{Calendar.MONDAY,Calendar.TUESDAY,Calendar.WEDNESDAY,Calendar.THURSDAY,Calendar.FRIDAY,Calendar.SATURDAY,Calendar.SUNDAY};

	public void setWeekOfMonth(int _weekOfMonth) {
		this.week.setWeekOfMonth(_weekOfMonth);
	}

	public int getWeekOfMonth() {
		return week.getWeekOfMonth();
	}

	public void setMonth(int monthOfYear) {
		this.week.setMonth(monthOfYear);
	}

	public Month getMonth() {
		return week.getMonth();
	}

	public void setMondayTreshold(double _mondayTreshold) {
		this._mondayTreshold = _mondayTreshold;
	}

	public double getMondayTreshold() {
		return _mondayTreshold;
	}

	public void setTuesdayTreshold(double _tuesdayTreshold) {
		this._tuesdayTreshold = _tuesdayTreshold;
	}

	public double getTuesdayTreshold() {
		return _tuesdayTreshold;
	}

	public void setWednesdayTreshold(double _wednesdayTreshold) {
		this._wednesdayTreshold = _wednesdayTreshold;
	}

	public double getWednesdayTreshold() {
		return _wednesdayTreshold;
	}

	public void setThursdayTreshold(double _thursdayTreshold) {
		this._thursdayTreshold = _thursdayTreshold;
	}

	public double getThursdayTreshold() {
		return _thursdayTreshold;
	}

	public void setFridayTreshold(double _fridayTreshold) {
		this._fridayTreshold = _fridayTreshold;
	}

	public double getFridayTreshold() {
		return _fridayTreshold;
	}

	public void setSaturdayTreshold(double _saturdayTreshold) {
		this._saturdayTreshold = _saturdayTreshold;
	}

	public double getSaturdayTreshold() {
		return _saturdayTreshold;
	}

	public void setSundayTreshold(double _sundayTreshold) {
		this._sundayTreshold = _sundayTreshold;
	}

	public double getSundayTreshold() {
		return _sundayTreshold;
	}

	public double getDayAmount(int dayOfWeek) throws Exception {
		switch (dayOfWeek) {
		case Calendar.MONDAY:
			return getMondayTreshold();
		case Calendar.TUESDAY:
			return getTuesdayTreshold();
		case Calendar.WEDNESDAY:
			return getWednesdayTreshold();
		case Calendar.THURSDAY:
			return getThursdayTreshold();
		case Calendar.FRIDAY:
			return getFridayTreshold();
		case Calendar.SATURDAY:
			return getSaturdayTreshold();
		case Calendar.SUNDAY:
			return getSundayTreshold();
		default:
			throw new Exception("day of week invalide");
		}
	}

	public void setDayAmount(int dayOfWeek, double amount) throws Exception {
		switch (dayOfWeek) {
		case Calendar.MONDAY:
			setMondayTreshold(amount);
			break;
		case Calendar.TUESDAY:
			setTuesdayTreshold(amount);
			break;
		case Calendar.WEDNESDAY:
			setWednesdayTreshold(amount);
			break;
		case Calendar.THURSDAY:
			setThursdayTreshold(amount);
			break;
		case Calendar.FRIDAY:
			setFridayTreshold(amount);
			break;
		case Calendar.SATURDAY:
			setSaturdayTreshold(amount);
			break;
		case Calendar.SUNDAY:
			setSundayTreshold(amount);
			break;
		default:
			throw new Exception("day of week invalide..." + dayOfWeek);
		}
	}

	public ArrayList<DailyThreshold> getDailyThreshold() {
		ArrayList<DailyThreshold> daily_thresholds = new ArrayList<DailyThreshold>();
		daily_thresholds.add(new DailyThreshold(getMondayTreshold(),Calendar.MONDAY, getWeekOfMonth(), getMonth().getMonthOfYear()));
		daily_thresholds.add(new DailyThreshold(getTuesdayTreshold(),Calendar.TUESDAY, getWeekOfMonth(), getMonth().getMonthOfYear()));
		daily_thresholds.add(new DailyThreshold(getWednesdayTreshold(),Calendar.WEDNESDAY, getWeekOfMonth(), getMonth().getMonthOfYear()));
		daily_thresholds.add(new DailyThreshold(getThursdayTreshold(),Calendar.THURSDAY, getWeekOfMonth(), getMonth().getMonthOfYear()));
		daily_thresholds.add(new DailyThreshold(getFridayTreshold(),Calendar.FRIDAY, getWeekOfMonth(), getMonth().getMonthOfYear()));
		daily_thresholds.add(new DailyThreshold(getSaturdayTreshold(),Calendar.SATURDAY, getWeekOfMonth(), getMonth().getMonthOfYear()));
		daily_thresholds.add(new DailyThreshold(getSundayTreshold(),Calendar.SUNDAY, getWeekOfMonth(), getMonth().getMonthOfYear()));
		
		return daily_thresholds;
	}
}
